package com.yunji.order.emuns;

import com.yunji.common.utils.bean.BeanUtils;
import lombok.Getter;

import java.util.Objects;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.order.emuns
 * @Title: OrderStatus
 * @Description: 订单状态
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-04-10 15:26:19      V1.0        HuaAo       新建类
 */
@Getter
public enum OrderStatusEnum {
    WAIT_PAYING(0, "待支付"),
    //PAID(1, "支付中"),
    PAY_SUCCESS(2, "支付成功"),
    //ORDER_FINISH(3, "已完成"),
    ORDER_CANCEL(-1, "已关闭");

    private final Integer code;
    private final String value;

    OrderStatusEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public static String get(Integer code) {
        if (BeanUtils.isNull(code)) {
            return null;
        }
        OrderStatusEnum[] enums = OrderStatusEnum.values();
        for (OrderStatusEnum e : enums) {
            if (Objects.equals(e.code, code)) {
                return e.value;
            }
        }
        return null;
    }

    // 根据 code 获取枚举
    public static OrderStatusEnum fromCode(int code) {
        for (OrderStatusEnum status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("未知的订单状态 code：" + code);
    }
}
